#include <iostream>
#include <istream>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

static int RESULTS_PER_PAGE = 10;

struct Result{
	int relevance;
	string url;
	Result() : relevance(0) {}

};
istream& operator>>(istream& input, Result& res){
	input >> res.url >> res.relevance;
	return input;
}
ostream& operator<<(ostream& os, const Result& res){
	os << res.url;
	return os;
}

vector<Result> findLuck(const vector<Result>& res){
	int max = 0;
	vector<Result> retval;
	for(size_t i = 0; i < res.size(); ++i){
		if(res[i].relevance > max){
			retval.clear();
			retval.push_back(res[i]);
			max = res[i].relevance;
		}
		else if(res[i].relevance == max){
			retval.push_back(res[i]);
		}
	}
	return retval;
}

int main(){
	int cases;
	cin >> cases;
	ostringstream output;
	for(int current = 1; current <= cases; current++){
		vector<Result> page;
		for(int i = 0; i < RESULTS_PER_PAGE; ++i){
			//create Result tmp
			Result tmp;
			//pass input into Result object
			cin >> tmp;
			//push the Result object onto the vecotr
			page.push_back(tmp);
		}
		vector<Result> final = findLuck(page);
		output << "Case #" << current << ":" << endl;
		for(size_t i = 0; i < final.size(); ++i){
			output << final[i] << endl;
		}
	}
	cout << output.str();
}
